﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ServiceConfigurationSchema"
    targetNamespace="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"
    elementFormDefault="qualified"
    xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"
    xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:complexType name="ConfigurationSetting">
    <xs:annotation>
      <xs:documentation>
        A configuration setting is a mapping of a name to a string value.
      </xs:documentation>
    </xs:annotation>
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The name of the configuration setting. The name should match the name of a setting
          declared in the service definition.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="value" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The value of the configuration setting.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="Certificate">
    <xs:annotation>
      <xs:documentation>
        A certificate setting is a mapping of a name of a certificate to the identifying value (ie. SHA1 thumbprint).
      </xs:documentation>
    </xs:annotation>
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The name of the certificate. The name should match the name of a certificate
          declared in the service definition.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="thumbprint" type="ThumbprintType" use="required">
      <xs:annotation>
        <xs:documentation>
          The digest (or thumbprint) of the certificate data used to uniquely identify a certificate.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="thumbprintAlgorithm" type="ThumbprintAlgorithmTypes" use="required">
      <xs:annotation>
        <xs:documentation>
          The hash algorithm that generates a digest of data (or thumbprint)
          for digital signatures such as MD5, SHA1, SHA256. This is different than
          the algorithm used in creating the signature inside the certificate.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:simpleType name="ThumbprintAlgorithmTypes">
    <xs:restriction base="xs:string">
      <xs:enumeration value="sha1" >
        <xs:annotation>
          <xs:documentation>
            Algorithm currently used in certmgr.msc to display thumbprint.
          </xs:documentation>
        </xs:annotation>
      </xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ThumbprintType">
    <xs:annotation>
      <xs:documentation>
        A thubmprint must be a non-empty string of hex digits.
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
      <xs:pattern value="[0-9A-Fa-f\s]*" />
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="TargetSetting">
    <xs:attribute name="count" use="required" type="xs:int">
      <xs:annotation>
        <xs:documentation>
          The number of role instances that are required.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="OsImageSetting">
    <xs:attribute name="href" type="xs:anyURI" use="required">
      <xs:annotation>
        <xs:documentation>
          URI to an image in the virtual machine image repository 
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>
  
  <xs:complexType name ="RoleSettings">
    <xs:all>
      <xs:element name="OsImage" type="OsImageSetting" minOccurs="0" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>
            TODO
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="ConfigurationSettings" minOccurs="0" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>
            Values for the configuration settings names declared in the
            service definition to string values.
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Setting" type="ConfigurationSetting" minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="Instances" type="TargetSetting" minOccurs="1" maxOccurs="1"/>
      <xs:element name="Certificates" minOccurs="0" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>
            Thumbprint mapping values for the certificates declared by name in the service definition.
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Certificate" type="Certificate" minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:all>
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The name of the role. The name should match the name of the role in the service definition.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="ServiceConfiguration">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Role" type="RoleSettings">
        <xs:annotation>
          <xs:documentation>
            The configuration and instance settings for a role.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="serviceName" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>
          The name of the service must match the name of the service in the service definition.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="osFamily" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation>
          The family of the guest operating system on which this service should run. If omitted, the service runs on the default guest operating system.
          See Configuring Operating System Versions (http://go.microsoft.com/fwlink/?LinkId=179590) for more information.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="osVersion" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation>
          The version of the guest operating system on which this service should run. If omitted, the service runs on the default guest operating system.
          See Configuring Operating System Versions (http://go.microsoft.com/fwlink/?LinkId=179590) for more information.
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:element name="ServiceConfiguration" type="ServiceConfiguration"></xs:element>
</xs:schema>
